Test Series - Data Structure

Test Number 63/115

Q: What is a weight balanced tree?
A. A binary tree that stores the sizes of subtrees in nodes
B. A binary tree with an additional attribute of weight
C. A height balanced binary tree
D. A normal binary tree
Solution: Unlike AVL and redblack trees which uses height and color as book keeping information, weight balanced trees use the size of subtrees.
Q: What are the applications of weight balanced tree?
A. dynamic sets, dictionaries, sequences, maps
B. heaps
C. sorting
D. storing strings
Solution: They are a type of self balancing trees which are mostly used in storing key-value pairs, which is mostly used in functional programming languages. they are very useful to maintain big set of ordered objects.
Q: A node of the weight balanced tree has
A. key, left and right pointers, size
B. key, value
C. key, size
D. key
Solution: As a weight balanced tree stores height of the subtrees, we need to use size as an additional attribute to every node. also value(for mappings) may be an optional attribute.
Q: The size value of various nodes in a weight balanced tree are
leaf – zero
internal node – size of it’s two children
is this true?
A. true
B. false
C. ..
D. ..
Solution: Explanation: Size of a node k is size[k] = size[k.left] + 1 + size[k.right] and based on this the weight will be given as weight[k] = size[k] + 1.
Q: What is the condition for a tree to be weight balanced. where a is factor and n is a node?
A. weight[n.left] >= a*weight[n] and weight[n.right] >= a*weight[n].
B. weight[n.left] >= a*weight[n.right] and weight[n.right] >= a*weight[n].
C. weight[n.left] >= a*weight[n.left] and weight[n.right] >= a*weight[n].
D. weight[n] is a non zero
Solution: The tree is said to be a-balanced if the condition is satisfied. and ‘a’ value will be determined during tree formation. large value of ‘a’ is more effective.
Q: What are the operations that can be performed on weight balanced tree?
A. all basic operations and set intersection, set union and subset test
B. all basic operations
C. set intersection, set union and subset test
D. only insertion and deletion
Solution: The speciality of a weight balanced tree is a part from basic operations we can perform collective operations like set intersection, which helps in rapid prototyping in functional programming languages.
Q: Consider a weight balanced tree such that, the number of nodes in the left sub tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the farthest leaf) of such a tree on k nodes can be described as
A. log2 n
B. log4/3 n
C. log3 n
D. log3/2 n
Solution: Total number of nodes can be described by the recurrence T(n) = T((n-1)/3)) + T(2(n-1)/3) + 1 T(1) = 1. height of the tree will be H(n) = H(2/3(n-1)) + 1, H(1). drawing a recurrence tree and the cost at each level is 1 and the height will be log(3/2)n.
Q: Why the below pseudo code where x is a value, wt is weight factor and t is root node can’t insert?

WeightBalanceTreeNode insert(int x, int wt, WeightBalanceTreeNode k) :
 
           if (k == null)
                k = new WeightBalanceTreeNode(x, wt, null, null)
           else if (x < t.element) :
 
                k.left = insert (x, wt, k.left)
                if (k.left.weight < k.weight)
                    k = rotateWithRightChild (k)
 
            else if (x > t.element) :
 
                k.right = insert (x, wt, k.right)
                if (k.right.weight < k.weight)
                    k = rotateWithLeftChild (k)
A. when x>t. element Rotate-with-left-child should take place and vice versa
B. the logic is incorrect
C. the condition for rotating children is wrong
D. insertion cannot be performed in weight balanced trees
Solution: The rotations of children must be interchanged in the code.
Q: What does the below definations convey?
i. A binary tree is balanced if for every node it is gonna hold that the number of inner nodes in the left subtree and the number of inner nodes in the right subtree differ by at most 1.
ii. A binary tree is balanced if for any two leaves the difference of the depth is at most 1.
A. weight balanced and height balanced tree definations
B. height balanced and weight balanced tree definations
C. definations of weight balanced tree
D. definations of height balanced tree
Solution: They are the definations of weight and height balanceness. height balanced trees wont convey weight balanceness but opposite can be true.
Q: Elements in a tree can be indexed by its position under the ordering of the keys and the ordinal position of an element can be determined, both with good efficiency.
A. true
B. false
C. ..
D. ..
Solution: In a weight balanced tree we can even store the key information so as to use as a key value pair.

You Have Score    /10